﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    // db = new DB.BestLifeDBDataContext();

    BestLifeDBDataContext db = new BestLifeDBDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void RadButton1_Click(object sender, EventArgs e)
    {
       Tbl_Product tablepro = new Tbl_Product();

       tablepro.Pro_ID = proid.Text;
       tablepro.Code = code.Text;
       tablepro.Description = des.Text;
       tablepro.Pro_Name = proname.Text;
       tablepro.Pro_Price = proprice.Text;
       tablepro.Point_Value = int.Parse(pv.Text);
       tablepro.Pro_Type = protype.Text;
       tablepro.Pro_Image = proImg.TargetFolder;
       tablepro.Cat_ID = catoid.Text;

       db.Tbl_Products.InsertOnSubmit(tablepro);
       db.SubmitChanges();

    }
    protected void RadButton2_Click(object sender, EventArgs e)
    {

        Tbl_Product up = new Tbl_Product();
        up = db.Tbl_Products.Single(cacc =>cacc.Pro_ID==proid.Text);

        up.Pro_ID = proid.Text;
        up.Code = code.Text;
        up.Description = des.Text;
        up.Pro_Name = proname.Text;
        up.Pro_Price = proprice.Text;
        up.Point_Value = int.Parse(pv.Text);
        up.Pro_Type = protype.Text;
        up.Pro_Image = proImg.TargetFolder;
        up.Cat_ID = catoid.Text;

        db.SubmitChanges();
    }
    protected void RadButton4_Click(object sender, EventArgs e)
    {
        Tbl_Product se = new Tbl_Product();
        se = db.Tbl_Products.Single(cacc => cacc.Pro_ID == proid.Text);

        proid.Text = se.Pro_ID;
        code.Text = se.Code;
        des.Text = se.Description;
        proname.Text = se.Pro_Name;
        proprice.Text = se.Pro_Price;
        pv.Text = se.Point_Value.ToString();
        protype.Text = se.Pro_Type;

        catoid.Text = se.Cat_ID;

        Label1.Text = "Search ok";
    }
    protected void RadButton3_Click(object sender, EventArgs e)
    {
        Tbl_Product del = new Tbl_Product();
        del = db.Tbl_Products.Single(cacc => cacc.Pro_ID== proid.Text);

        db.Tbl_Products.DeleteOnSubmit(del);
        db.SubmitChanges();
    }
}